<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>InitPHP框架 PHP框架 - A PHP Framework - 服务层Service API</title>
<link href="static/common.css" type="text/css" rel="stylesheet" />
<meta name="keywords" content="php框架，国产php框架, initphp框架，MVC，分层体系" />
<meta name="description" content="initphp框架是一款国产php框架。initphp框架主要基于MVC模式，具备代码清晰，操作简单，功能齐全，开发快速，高效安全等特点，是您选择php框架的首选。" />
</head>
<body>
<div class="header">
  <div class="header_nav">InitPHP (A PHP Framework) 用户手册</div>
  <div class="header_div">
    <div class="header_title">第6章 6.3 服务层Service API</div>
    <div class="header_right"><a href="6_2_4.htm">上一页</a> <a href="6_4.htm">下一页</a> </div>
  </div>
</div>
<div class="title">目录</div>
<ul style="list-style:none;">
  <li><a href="#$this->service->parse_data">$this->service->parse_data</a></li>
  <li><a href="#$this->service->return_msg">$this->service->return_msg</a></li>
</ul>
<div class="nav"></div>
<div class="title">1. $this->service->parse_data() 字段校验-用于进入数据库的字段映射<a name="$this->service->parse_data"></a></div>
<div class="title">
  <h3>接口描述：</h3>
</div>
<p> 字段校验-用于进入数据库的字段映射。在Service中使用</p>
<div class="title">
  <h3>参数：</h3>
</div>
<table>
  <tr>
    <th style="width:20%;"> 参数 </th>
    <th style="width:20%;"> 类型 </th>
    <th style="width:10%;"> 是否必须 </th>
    <th style="width:50%;"> 描述 </th>
  </tr>
  <tr>
    <td>$field</td>
    <td>Array </td>
    <td>是</td>
    <td>可信任字段 array(array('field', 'int'))</td>
  </tr>
  <tr>
    <td>$data</td>
    <td>Array </td>
    <td>是</td>
    <td>传入的参数</td>
  </tr>
</table>
<div class="title">
  <h3>使用：</h3>
</div>
<pre id="PHP" class="prettyprint">
public function test() {
	$field = array(
		array('username', ''),
		array('age', 'int'),
		array('password', '')
	);
	$data = array('username' => 'init', 'age' => 10, 'password' => '123456');
	$result = $this->service->parse_data($field, $data);
	$this->getTestDao()->test($result);
}
</pre>
<div class="nav"></div>
<div class="title">2. $this->service->return_msg($status, $msg, $data = '') service特殊情况-数据返回组装器<a name="$this->service->return_msg"></a></div>
<div class="title">
  <h3>接口描述：</h3>
</div>
<p>Service经常会有很多复杂的验证情况，需要传递给Controller，可以通过return_msg返回一个结构体。在Service中使用</p>
<div class="title">
  <h3>参数：</h3>
</div>
<table>
  <tr>
    <th style="width:20%;"> 参数 </th>
    <th style="width:20%;"> 类型 </th>
    <th style="width:10%;"> 是否必须 </th>
    <th style="width:50%;"> 描述 </th>
  </tr>
  <tr>
    <td>$status</td>
    <td>Bool </td>
    <td>是</td>
    <td>状态，true|false</td>
  </tr>
  <tr>
    <td>$msg</td>
    <td>String</td>
    <td>是</td>
    <td>提示信息</td>
  </tr>
  <tr>
    <td>$data</td>
    <td>Array</td>
    <td>是</td>
    <td>传递的参数</td>
  </tr>
</table>
<div class="title">
  <h3>使用：</h3>
</div>
<pre id="PHP" class="prettyprint">
class testService extends Service {
	public function test() {
		return $this->service->return_msg(0, '访问错误', '');
	}
	/**
	 * @return testDao
	 */
	private function getTestDao() {
		return InitPHP::getDao('test', 'test');
	}
	/**
	 * @return testaDao
	 */
	private function getTestaDao() {
		return InitPHP::getDao('testa', 'test');
	}
}
</pre>
<div class="nav"></div>
<div class="footer">版权所有：<a href="">http://initphp.com</a> InitPHP (A PHP Framework) By @Aliyun_zhuli</div>
<script src="static/jquery.js" type="text/javascript"></script>
<link href="static/prettify/prettify.css" rel="stylesheet" type="text/css">
<script src="static/prettify/prettify.js" type="text/javascript"></script>
<script type="text/javascript" src="static/comm.js"></script>
</body>
</html>
